import { createRouter, createWebHistory,createWebHashHistory, RouteRecordRaw } from 'vue-router'
// Vue3 的router 
// createRouter 创建路由对象
// createWebHistory 创建历史模式的对象
// createWebHashHistory 创建hash模式路由
// RouteRecordRaw 对route配置项的约束
import Home from '../views/Home.vue'
const routes: Array<RouteRecordRaw> = [
  {
    path: '/',
    name: 'Home',
    component: Home
  },
  {
    path:"/cate",
    name:"cate",
    component:()=>import("../views/Category.vue")
  },
  {
    name:"my",
    path:"/my",
    component:()=>import("../views/My.vue")
  },
  {
    name:"jsxy",
    path:"/jsxy",
    component:()=>import("../views/Jsxy.vue")
  },
  {
    path:"/cart",
    name:"cart",
    component:()=>import("../views/Cart.vue")
  },
  {
    path: '/about/:pid?',
    name: 'About',
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import(/* webpackChunkName: "about" */ '../views/About.vue')
  }
]

const router = createRouter({
  // process.env.BASE_URL 本地环境的基本路径
  history: createWebHistory(process.env.BASE_URL),
  routes
})
// 路由守卫
router.beforeEach((to,from,next)=>{
  console.log(to)
  console.log(from)
  next()
})
export default router
